/******************************************************************************
*
* MODULE:    AluControl.v
* DEVICE:     AluControl 
* PROJECT:   Tarea 3 Diseño Electronico Digital
* AUTHOR:    Ricardo Dávila Castro   
* DATE:      2010 21:15:58
*
* ABSTRACT:   AluControl Ejercicio 1
*            
******************************************************************************/

`ifndef 	ALUCONTROL
`define    ALUCONTROL
`define  ADD = 'h 2
`define  SUB = 'h 6
`define  AND = 'h 0
`define  OR  = 'h 1

module AluControl(
input [5:0] Opcode, //pa la add inmediata
input [1:0] ALUOp, 
input [5:0] Funct, 
output reg [4:0]Operacion
);


parameter [1:0] DATATRANSFER = 00,
                REGISTER= 2'b 01,
                BRANCH = 2'b 10,
                IMMEDIATE = 2'b 11;

always @ (*) 
  begin
   //Operacion = 4'h 2;
   case (ALUOp)
    DATATRANSFER: Operacion = 4'h 2;  //suma
    REGISTER: Operacion = 4'h 6; //resta
    BRANCH: case (Funct)
                    'h 20: Operacion `ADD;//4'h 2; //R-type add
                    'h 21: Operacion = 'h 0D; //R-type nand
                    'h 22: Operacion = 'h 06; //R-type subtract
                    'h 23: Operacion = 'h 04; //R-type xnor
                    'h 24: Operacion = 'h 00; //R-type and
                    'h 25: Operacion = 'h 01; //R-type or
                    'h 26: Operacion = 'h 03; //R-type xor
                    'h 27: Operacion = 'h 0E; //R-type shift right
                    'h 28: Operacion = 'h 0C; //R-type nor
                    'h 29: Operacion = 'h 08; //R-type add with carry
                    'h 2A: Operacion = 'h 07; //R-type set on less than
                    'h 2B: Operacion = 'h 09; //R-type subs with borrow
                    'h 2C: Operacion = 'h 0A; //R-type increment
                    'h 2D: Operacion = 'h 0B; //R-type decrement
                    'h 2E: Operacion = 'h 0F; //R-type shift left
                    'h 2F: Operacion = 'h 05; //R-type transfer
                    'h 30: Operacion = 'h 10; //R-type clear
                    'h 31: Operacion = 'h 11; //R-type Rotate Right
                    'h 32: Operacion = 'h 12; //R-type Rotate Left
                    'h 33: Operacion = 'h 13; //R-type Arithmetic shift Right 
                    'h 34: Operacion = 'h 14; //R-type Arithmetic shift Left
                    
                       default: 
                          Operacion = 4'h x;
            endcase                                
    IMMEDIATE: begin if (Opcode==4'h7) Operacion = 4'h 2; end
    default :
      Operacion = 4'h x;
    endcase
end
endmodule
`endif